import Vue 				 from 'vue'
import VueRouter   from 'vue-router'
import store       from 'store/index'
import { Message, Form, FormItem, Input} from 'element-ui'  
import mainpageRouter  from 'router/mainpage/mainpageRouter'
import myinfoRouter  from 'router/myinfo/myinfoRouter'
import goodsRouter  from 'router/goods/goodsRouter'
import VueClipboard from 'vue-clipboard2'
// 导入富文本编辑组件
import VueQuillEditor from "vue-word-editor";
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

const Login   = ()=>import('views/Login')
const Login_1   = ()=>import('views/Login_1')
const Signup   = ()=>import('views/Signup')
const Admin   = ()=>import('views/Admin')
const Miss 		= ()=>import('views/common/Miss')
const Index 	= ()=>import('views/common/Index')


Vue.use(VueRouter)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(VueClipboard)
Vue.use(VueQuillEditor, /* { default global options } */)

const routes = [
	{
		path:'',
		redirect:'/login'
	},
	{
		path:'/login',
		component: Login
	},
	{
		path:'/login_1',
		component: Login_1
	},
	{
		path:'/signup',
		component: Signup
	},
	{
		path:'/admin',
		component: Admin,
		children:[
			{
				path:'',
				redirect:'index',
			},
			{
				path:'index',
				component:Index,
			},
			mainpageRouter,
			myinfoRouter,
			goodsRouter,
			{
				path:'*',
				component:Miss
			},

		]
	}
	
]

const router  = new VueRouter({
	routes:routes,
})
// 解决navigation(不一定生效)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
	return originalPush.call(this, location).catch(err => err)
}

//利用路由守卫判断用户是否登录..
router.beforeEach((to,from,next)=>{
	//判断是否登录..        盲猜没有jwt，并且登录后路径无法为/path
	// if((to.path != '/login') && (store.state.jwt == '')){
	// 	Message({
	// 		message: '您未登录,请先登录',
	// 		type: 'error',
	// 		duration: 3 * 1000
	// 	})
	// 	// next('/login')
	// 	next();
	// }
	//判断是否重复登录..
	// if(to.path == '/login' && store.state.jwt != ''){
	// 	Message({
	// 		message: '请不要重复登录',
	// 		type: 'error',
	// 		duration: 3 * 1000
	// 	})
	// 	next('/admin/index')
	// }
	
	//判断跳转路由是否存在权限..
	// let all_rule = store.state.pathArr
	// all_rule.push('/admin/index')
	// all_rule.push('/admin/404')
	// all_rule.push('/login')
	// let power = new Set(all_rule)
	// if(!power.has(to.path) && (store.state.jwt != '')){
	// 	Message({
	// 		message: '没有权限,请授权之后使用',
	// 		type: 'error',
	// 		duration: 3 * 1000
	// 	})
	// 	next(from.path)
	// }
  next()
})
export default router